/**
  接口配置地址
**/ 
var urlText="http://art.sanploy.cn/";
layui.define(["laytpl","jquery","flow"],function(exports){
	var laytpl = layui.laytpl,
		flow = layui.flow,
		$ = layui.jquery;
  //配置接口地址
  var obj = {
   	banner:urlText+"banner",//banner接口
   	activity:urlText+"activity/list",//所有活动分页接口
   	category:urlText+"category/list",//所有活动分类接口
   	activity_xq:urlText+"activity",//根据获取id活动详情接口
   	article:urlText+"article/list",//获取新闻接口
   	article_xq:urlText+"article",	//获取某个新闻
   	article_cat:urlText+"category/article/list",//获取所有新闻分类
   	education_cat:urlText+"category/list",//获取教育教师分类
   	lecturer:urlText+"lecturer/list",//根据分类获取教育教师
   	lecturer_xq:urlText+"lecturer",//根据分类获取教育教师
   	school:urlText+"team/list",//机构接口
   	school_cat:urlText+"category/list",//获取机构分类	
   	school_xq:urlText+"team",
   	school_activity:urlText+"activity/activity",//查看机构活动		//?teamId=12
    wxLogin:urlText+"wxLogin/test",//token测试接口
    user_order:urlText+"user/order",  //活动报名
   	user_card:urlText+"user/apply/real",//实名认证
   	user_outfit:urlText+"user/apply/team",//机构认证
   	user_lecturer:urlText+"user/apply/lecturer",//讲师认证
   	user_school:urlText+"user/apply/school",//学校认证
	  /*// 认证
	  postData:function (reqUrl,reqData,success) {
		  $.ajax({
			  url:reqUrl,
			  type:"POST",
			  data:reqData,
              async:false,
              success: function (res) {
                  //console.log(data);
                  success?success(res):function(){};
              },
              error: function (res) {
                  console.log(res);
              }
		  })
      },*/
   	//无分页列表渲染数据公共方法
	dataListF:function (apiUrl,dataElem,listElem){
		$.ajax({
			url:apiUrl,
			type:"get",
			dataType:"json",
			async:false,
			success:function(data){
				if(data.meta.code==200){
					if(data.meta.type=="SUCCESSFUL"){
						var getTpl = document.getElementById(dataElem).innerHTML;
						var view = document.getElementById(listElem);
						laytpl(getTpl).render(data, function(html){
							console.log(data);
						  view.innerHTML = html;
						})
						//执行banner
					}else{
						console.log("banner 获取失败");
					}
				}
			}
		});
	},
	//公共详情
	details:function(apiUrl,dataElem,listElem){
			$.ajax({
				type:"get",
				url:apiUrl,
				async:false,
				success:function(data){
						if(data.meta.code==200){
							if(data.meta.type=="SUCCESSFUL"){
								console.log(data);
								var getTpl = document.getElementById(dataElem).innerHTML,
									view=document.getElementById(listElem);
									laytpl(getTpl).render(data.data,function(html){
										view.innerHTML=html;
									});
							}else{
								console.log("获取失败");
							}
						}
				}
			})
		},
	//公共下拉分页数据列表渲染
	dataListLoad:function(catId,elem,apiUrl,elemHtml){
		flow.load({
		    elem: elem, //流加载容器
		    //scrollElem: elem //滚动条所在元素，一般不用填，此处只是演示需要。
		    done: function(page, next){ //执行下一页的回调
		      //模拟数据插入
		       var list = [];
				$.ajax({
				url:apiUrl,
				type:"get",
				data:{categoryId:catId,currentPage:page,pageSize:5},
				dataType:"json",
				success:function(data){
					if(data.meta.code==200){
						if(data.meta.type=="SUCCESSFUL"){
							console.log(data.data.list);
							var getTpl = document.getElementById(elemHtml).innerHTML;
							laytpl(getTpl).render(data, function(html){
							  	list.push(html);
							})
							next(list.join(''), page < data.data.totalPage);    
						}else{
							console.log("数据加载失败");
						}
					}
				}
				})
		    }
	  });
	},
	//得到参数
	getUrlJoin:function(name)
	{
	     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	     var r = window.location.search.substr(1).match(reg);
	     if(r!=null)return  unescape(r[2]); return null;
	},
	//通用跳转链接
	linkEvent:function(elem,elem1){
		$(elem).on("click",elem1,function(e){
			var page=$(this).attr("data-href");
			var id=$(this).attr("data-id");
			window.location.href=page+"?id="+id;
		});
	}
  };
  //提供外部使用公共
  exports('allApi', obj);
}); 

/*
<script type="text/html" id="data-banner">
	 {{#  layui.each(d.data, function(index, item){ }}
   		<div class="swiper-slide bj-cs"><img src="{{urlText}}{{item.bannerPath}}" alt="{{item.bannerDescription}}"></div>
   	 {{#  }); }}
	 {{#  if(d.data.length === 0){ }}
   	   暂无上传
   	 {{#  } }} 
	</script>
*/